import App from './App.vue'
import { createApp, createVNode } from 'vue'
import router from './router'
import { $utils, $auth } from './utils'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/display.css'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import * as AntDesignIconsVue from '@ant-design/icons-vue'
import { isAuthorised } from './router'
import pinia from './stores/index'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import Pagination from '@/components/Pagination.vue'
import naive from 'naive-ui'

const app = createApp(App)
app.config.devtools = true // 开发环境开启vue-devtools
app.config.productionTip = false // 阻止vue在启动时生成生产提示

// 清除localStorage的方法
app.config.globalProperties.clearToken = () => {
  localStorage.clear()
}

app.config.globalProperties.$auth = $auth
app.config.globalProperties.$utils = $utils // 全局挂载工具类

app.config.globalProperties.isAuthorised = isAuthorised

for (const [key, component] of Object.entries(
  ElementPlusIconsVue,
)) {
  app.component(key, component)
}
for (const [key, component] of Object.entries(
  AntDesignIconsVue,
)) {
  app.component(key, component)
}

const Icon = (props) => {
  const { icon } = props
  return createVNode(ElementPlusIconsVue[icon])
}
app.component('Icon', Icon)

// 全局注册分页组件
app.component('Pagination', Pagination)

app.use(pinia)
app.use(router).mount('#app')
app.use(naive)
app.use(ElementPlus, {
  locale: zhCn,
})

// Ant Design
import { DatePicker } from 'ant-design-vue'

app.use(DatePicker)
